    const Koa = require('koa')
    const Router = require('koa-router')

    // 实例化应用
    const app = new Koa()

    async function logger(ctx, next) {
        console.log(`${ctx.method} ${ctx.path}`);
        await next()
    }
    // 实例化路由
    const router = new Router()
    router.get('/',logger, async (ctx) => {
        ctx.body = 'Hello world'
    })


    router.get('/user', async (ctx) => {
        ctx.body = 'User'
    })

    // 挂载路由中间件
    app.use(router.routes())
    app.use(router.allowedMethods())

    app.listen(8899, () => {
        console.log('listen on 8899');
    })